package org.aspectsense.middleware.scheduler;


/**
 * Immutable implementation of a scheduler event.
 *
 * @author Nearchos Paspallis [nearchos@cs.ucy.ac.cy]
 *         Date: Feb 8, 2008
 *         Time: 11:47:25 AM
 */
public class Event 
{
    protected final Runnable runnable;
    protected final long minWaitTime;

    /**
     * Constructs a non-recurring scheduled event. Its semantics imply that the
     * specified runnable should be executed after some time, specified by the
     * minWaitTime. For example, if the minWaitTime is specified as 10000L,
     * then the corresponding event is scheduled for execution after 10
     * seconds.
     *
     * @param runnable the {@link Runnable} to be executed
     * @param minWaitTime the time period after which the {@link Runnable}
     * should be executed; expressed in milliseconds
     */
    public Event(final Runnable runnable, final long minWaitTime)
    {
        if(runnable == null)
        {
            throw new NullPointerException("Illegal null argument");
        }
        if(minWaitTime < 0)
        {
            throw new IllegalArgumentException("The minWaitTime cannot be "
                    + "negative: " + minWaitTime);
        }

        this.runnable = runnable;
        this.minWaitTime = minWaitTime;
    }

    public Runnable getRunnable()
    {
        return runnable;
    }

    public long getMinWaitTime()
    {
        return minWaitTime;
    }

    public String toString()
    {
        return "Event{runnable= " + runnable + ", minWaitTime="
                + minWaitTime + "}";
    }
}